import React,{Component} from 'react'
import {connect} from 'dva'
import {Card,WingBlank,WhiteSpace} from 'antd-mobile'
class Genius extends Component{
    constructor(){
        super();
    }
    componentDidMount(){
        this.props.dispatch({type:'info/getGeniusInfo',payload:'boss'});
    }
    handleClick(user){
        //console.log(this.props);
        this.props.history.push(`/chat/${user}`)
    }
    render(){
        return(
            <React.Fragment>
                 <WingBlank size="sm">
                    
                    {
                        this.props.data.map((item)=>{
                            return(
                                // 判断头像是否存在
                                item.avatar?(<div key={item._id}>
                                    <WhiteSpace size="sm"/>
                                    <Card onClick={()=>{this.handleClick(item._id)}}>
                                    <Card.Header
                                        
                                        title={item.user}
                                        thumb={require(`../../static/images/${item.avatar}.png`)}
                                        extra={<span>{item.title}</span>}
                                    />
                                    <Card.Body>
                                        <div>{item.desc.split('\n').map((item)=>{
                                            return (<div key={item} style={{marginTop:'10px'}}>{item}</div>)
                                        })}</div>
                                        <div style={{float:'right',position:'absolute',bottom:'0px',right:'10px'}}>{item.money}</div>
                                    </Card.Body>
                                   
                                    </Card>
                                    <WhiteSpace size="sm" />
                                    </div>):null
                            )
                        }      
                        )
                        
                    }
                    
                   
                </WingBlank>
            </React.Fragment>
        )
    }

}
const mapStateProps = (state)=>{
    return{
	    data:state.info.data,
    }
}
export default connect(mapStateProps)(Genius);